<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\StoreStyle;

class StoreGoods extends Model
{
    protected $table = 'store_goods';//
    
    protected $appends = ['updown_txt','style_txt'];
    
     /**
     * @return mixed
     */
    public function getUpdownTxtAttribute(){
        return $this->updown == 1 ? "上架中" : "下架中";
    } 
    
    public function getStyleTxtAttribute(){
    	$styleArr = explode(',',$this->style);
        $result = StoreStyle::whereIn('id',$styleArr)->get();
        
        $styleObjArr = [];
        foreach($result as $value){
        	$obj = ['id'=>$value->id,'name'=>$value->name];
        	$styleObjArr[] = $obj;
        }
        return json_encode($styleObjArr);
    } 

}
